最後來處理hit test , 讓虛擬物件回到還沒有被放置的狀態
override func touchesBegan(_ touches: Set<UITouch>,
with event: UIEvent?) {
DispatchQueue.main.async {
if let location = touches.first?.location(
in: self.sceneView) {
if let hit = self.sceneView.hitTest(location,
options: nil).first {
if hit.node.name == "myObject" {
hit.node.removeFromParentNode()
self.count += 1
}
} }
} }